import axiosInstance from '@/Auxiliary/Axios';

// 获取验证码图片
export const getCaptcha = async () => {
  try {
    const response = await axiosInstance.get('/api/captcha', {
      responseType: 'blob' // 设置响应类型为 blob 以处理图片
    });
    const url = window.URL.createObjectURL(new Blob([response.data]));
    return url;
  } catch (error) {
    console.error('获取验证码失败', error);
    throw error;
  }
};

// 验证验证码
export const verifyCaptcha = async (captcha:any) => {
  try {
    const response = await axiosInstance.post('/api/verify-captcha', {
      captcha
    });
    return response.data.valid; // 假设返回 { valid: true/false }
  } catch (error) {
    console.error('验证码验证失败', error);
    throw error;
  }
};

// 登录请求
export const login = async (username:any, password:any) => {
  try {
    const response = await axiosInstance.post('/api/login', {
      username,
      password
    });
    return response;
  } catch (error) {
    console.error('登录失败', error);
    throw error;
  }
};